<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>书页翻转轮播</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f0f0f0;
            perspective: 2000px;
        }

        .book-carousel {
            width: 800px;
            height: 500px;
            position: relative;
            transform-style: preserve-3d;
        }

        .book-container {
            width: 100%;
            height: 100%;
            position: relative;
            transform-style: preserve-3d;
        }

        .page {
            position: absolute;
            width: 100%;
            height: 100%;
            transform-origin: left center;
            transform-style: preserve-3d;
            transition: transform 1s ease;
            cursor: pointer;
        }

        .page-front, .page-back {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
            background: white;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            overflow: hidden;
        }

        .page-back {
            transform: rotateY(180deg);
        }

        .page img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .controls {
            position: fixed;
            bottom: 20px;
            display: flex;
            gap: 10px;
            z-index: 100;
        }

        .control-btn {
            padding: 10px 20px;
            background: #333;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .control-btn:hover {
            background: #555;
        }

        .page-number {
            position: absolute;
            bottom: 10px;
            right: 10px;
            padding: 5px 10px;
            background: rgba(0,0,0,0.5);
            color: white;
            border-radius: 3px;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="book-carousel">
        <div class="book-container">
            <div class="page" style="z-index: 5;">
                <div class="page-front">
                    <img src="../img/1 (1).png" alt="Page 1">
                    <div class="page-number">1</div>
                </div>
                <div class="page-back">
                    <img src="../img/1 (2).png" alt="Page 2">
                    <div class="page-number">2</div>
                </div>
            </div>
            <div class="page" style="z-index: 4;">
                <div class="page-front">
                    <img src="../img/1 (3).png" alt="Page 3">
                    <div class="page-number">3</div>
                </div>
                <div class="page-back">
                    <img src="../img/1 (4).png" alt="Page 4">
                    <div class="page-number">4</div>
                </div>
            </div>
            <div class="page" style="z-index: 3;">
                <div class="page-front">
                    <img src="../img/1 (5).png" alt="Page 5">
                    <div class="page-number">5</div>
                </div>
                <div class="page-back">
                    <img src="../img/1 (1).png" alt="Page 1">
                    <div class="page-number">1</div>
                </div>
            </div>
        </div>
    </div>
    <div class="controls">
        <button class="control-btn prev">上一页</button>
        <button class="control-btn next">下一页</button>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const pages = document.querySelectorAll('.page');
            const prevBtn = document.querySelector('.prev');
            const nextBtn = document.querySelector('.next');
            
            let currentPage = 0;
            const totalPages = pages.length;
            let isAnimating = false;

            function updateBook(direction) {
                if (isAnimating) return;
                isAnimating = true;

                const currentPageElement = pages[currentPage];
                const rotation = direction === 'next' ? -180 : 0;
                const initialRotation = direction === 'next' ? 0 : -180;

                currentPageElement.style.transform = `rotateY(${initialRotation}deg)`;

                setTimeout(() => {
                    currentPageElement.style.transform = `rotateY(${rotation}deg)`;
                    
                    setTimeout(() => {
                        if (direction === 'next') {
                            currentPage = (currentPage + 1) % totalPages;
                        } else {
                            currentPage = (currentPage - 1 + totalPages) % totalPages;
                        }
                        isAnimating = false;
                    }, 1000);
                }, 50);

                // Update z-index for proper page stacking
                pages.forEach((page, index) => {
                    const zIndex = index === currentPage ? totalPages : totalPages - Math.abs(currentPage - index);
                    page.style.zIndex = zIndex;
                });
            }

            prevBtn.addEventListener('click', () => {
                if (!isAnimating) updateBook('prev');
            });

            nextBtn.addEventListener('click', () => {
                if (!isAnimating) updateBook('next');
            });

            // Add hover effect
            pages.forEach(page => {
                page.addEventListener('mouseover', () => {
                    if (!isAnimating) {
                        page.style.transform = 'rotateY(-15deg)';
                    }
                });

                page.addEventListener('mouseout', () => {
                    if (!isAnimating) {
                        page.style.transform = 'rotateY(0deg)';
                    }
                });
            });

            // Auto play
            setInterval(() => {
                if (!isAnimating) {
                    updateBook('next');
                }
            }, 4000);
        });
    </script>
</body>
</html>